#include "TitleScene.h"
#include "Director.h"
#include "GameScene.h"

TitleScene::TitleScene(void)
	:_musicOnFlag(false), _logoOnTime(0.0f)
{
	_titleObject.initTexture(".//image/title.png");
	_titleObject.setCenter(Vector3f(0,0));

	_logoObject.initTexture(".//image/logo.png");
	_logoObject.setCenter(Vector3f(0,0));
}

TitleScene::~TitleScene(void)
{
}

void TitleScene::Update()
{
	if( _logoOnTime <= 0.0f )
	{
		_logoOnTime += 0.01f;
		//_logoObject.draw();
		return;
	}

	if( _musicOnFlag == false)
	{
		_musicOnFlag = true;
		SharedDirector()->GetSoundManager()->loadsound("field");
		SharedDirector()->GetSoundManager()->playsound("field");
	}

	_titleObject.draw();

	int downKey = 0;
	if( SharedDirector()->GetInput()->IsKeyUp(DIK_1) ) downKey = 1;
	else if( SharedDirector()->GetInput()->IsKeyUp(DIK_2) ) downKey = 2;
	else if( SharedDirector()->GetInput()->IsKeyUp(DIK_3) ) downKey = 3;

	
	if( SharedDirector()->GetInput()->IsLButtonClick() )
	{
		MousePos mp = *SharedDirector()->GetInput()->GetMousePos();

		if( hitRectToPoint(Vector3l(mp.x, mp.y), Vector3l(120,560), Vector3l(340, 650)) )
			downKey = 1;
		if( hitRectToPoint(Vector3l(mp.x, mp.y), Vector3l(500,560), Vector3l(730, 650)) )
			downKey = 2;
		if( hitRectToPoint(Vector3l(mp.x, mp.y), Vector3l(880,560), Vector3l(1120, 650)) )
			downKey = 3;
	}
	
	if( downKey != 0 )
	{
		SharedDirector()->GetSceneManager()->SelectScene("GameScene");
		((GameScene*)SharedDirector()->GetSceneManager()->GetScene("GameScene"))->reset(downKey);
	}

}

bool TitleScene::hitRectToPoint(Vector3l dot,Vector3l r1,Vector3l r2)
{
	if( r1.x <= dot.x && dot.x <= r2.x && r1.y <= dot.y && dot.y <= r2.y )
		return true;
	return false;
}
